
import { Component } from '@angular/core';
import { GlobalService } from '@services/global.service';
// import { App } from '@ionic/angular';
// import { LoginPage } from '@pages/login/login';
import { JPush } from '@jiguang-ionic/jpush/ngx';
import { CacheService } from '@services/cache.service';
import { Router } from '@angular/router';

@Component({
  selector: 'page404',
  templateUrl: 'page.html',
  styleUrls: ['style.scss']
})
export class Page404 {

  haveFunction = true;
  haveProject = true;

  constructor(
    public global: GlobalService,
    // public app: App,
    public jpush: JPush,
    private cache: CacheService,
    private router: Router
  ) {
      const functionPoint = this.cache.functionPoint;
      this.cache.companys.subscribe(res => {
        if (!res || res.length === 0) {
          this.haveProject = false;
        }
      });
      if (!functionPoint || functionPoint.length === 0) {
        this.haveFunction = false;
      }
  }

  ionViewWillEnter() {
    const elements = document.querySelectorAll('ion-tab-bar');
    if (elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display = 'flex';
      });
    }
  }

  ionViewWillLeave() {
    const elements = document.querySelectorAll('ion-tab-bar');
    if (elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display = 'none';
      });
    }
  }

  goLoginPage() {
    this.jpush.deleteAlias({
      alias: '',
      sequence: new Date().getTime()
    });
    this.cache.clearCache();
    this.global.isLogin = false;
    // this.app.getRootNav().setRoot(LoginPage);
    this.router.navigate(['login']);
  }

}
